Release 10.1A: OpenEdge Development:
Programming Interfaces


Sample ProDataSet to XML round-trip

One of the most important use cases for the features described in this chapter is that of the XML round-trip. XML can be a persistent storage mechanism between Progress sessions. For example, a mobile computing model could use XML as a persistent data store. Suppose, a sales representative could work off-line from the server with a local copy of selected records, limited to his accounts, stored as XML. The mobile application could read the XML and work locally. The changes made off-line by the sales representative on the records would be stored locally as an updated XML file, storing before-image data as well. When the sales representative reconnects to the system, the XML would be sent back to the application server to synchronize with enterprise application. The application code could decide whether to apply the remote changes or overwrite with server changes. The before-image data could be used to compare changes that might have been made while the sales representative was working remotely.”

All you need to do is create a an XML write procedure to store your data and an XML read procedure to retrieve it. Of course, you must ensure that the min-xmlschema option is set to FALSE. That is, you want Progress to write its own XML Schema extensions so that the 4GL definitions are fully restored when the file is read back in.

This include file sets up a pair of temp-tables and a ProDataSet for the two code samples to use:

/* pi-tfx-writeSetup-6.i */ 
/* Creates two new static temp-tables and a ProDataSet. */ 
/* Definition for Temp-Table ttCust */ 
DEFINE TEMP-TABLE ttCust NO-UNDO 
    BEFORE-TABLE ttCustBef 
	    FIELD CustNum LIKE Customer.CustNum 
        FIELD Name LIKE Customer.Name  
             COLUMN-LABEL "Loyal Customer" 
             XML-NODE-TYPE "Attribute" 
        FIELD Country LIKE Customer.Country 
        FIELD Comments LIKE Customer.Comments FORMAT "x(40)" 
        INDEX CustNum IS PRIMARY UNIQUE CustNum 
        INDEX Name Name 
        INDEX Comments IS WORD-INDEX Comments. 
/* Definition for Temp-Table ttOrder */ 
DEFINE TEMP-TABLE ttOrd 
    BEFORE-TABLE ttOrdBef 
        FIELD OrderNum LIKE Order.OrderNum 
        FIELD CustNum LIKE Order.CustNum 
        FIELD OrderDate LIKE Order.OrderDate 
        INDEX OrderNum IS PRIMARY UNIQUE OrderNum 
        INDEX CustOrder IS UNIQUE CustNum OrderNum 
        INDEX OrderDate OrderDate. 
DEFINE DATASET dsCustomerOrders  
    FOR ttCust, ttOrd 
    DATA-RELATION custOrd FOR ttCust, ttOrd  
    REPOSITION RELATION-FIELDS (CustNum, CustNum) NESTED . 

The first code sample performs an XML write and informs you if it has been successful:

/* pi-tfx-write-6a.p */ 
/* Writes data from a static ProDataSet to an XML file. This demonstrates  
   the first half of a persistent storage mechanism through XML. */ 
{pi-tfx-parameterVarDefs.i} 
{pi-tfx-writeSetup-6.i} 
DEFINE VARIABLE returnValue AS LOGICAL NO-UNDO. 
DEFINE VARIABLE hPDS AS HANDLE. 
hPDS = DATASET dsCustomerOrders:HANDLE. 
/*** Before the method call, your application does work with its data. ***/ 
ASSIGN 
    cTargetType = "FILE" 
    cFile = "dsCustomerOrder.xml" 
    lFormatted = YES 
    cEncoding = ? 
    cSchemaLocation = ? 
    lWriteSchema = YES 
    lMinSchema = FALSE 
    lWriteBeforeImage = TRUE. 
returnValue = hPDS:WRITE-XML (cTargetType, cFile, lFormatted, cEncoding,  
                              cSchemaLocation, lWriteSchema, lMinSchema,  
                              lWriteBeforeImage). 
IF returnValue = FALSE THEN DO: 
    MESSAGE "WRITE-XML on ProDataSet failed!" VIEW-AS ALERT-BOX. 
    RETURN. 
END. 
ELSE  
    MESSAGE "Successful WRITE-XML on : " hPDS:NAME VIEW-AS ALERT-BOX. 

The second code sample performs an XML read and informs you if it has been successful:

/* pi-tfx-write-6b.p */ 
/* Reads and writes the data to and from a static ProDataSet to an XML file. */ 
{pi-tfx-parameterVarDefs.i} 
{pi-tfx-writeSetup-6.i} 
DEFINE VARIABLE returnValue AS LOGICAL NO-UNDO. 
DEFINE VARIABLE hPDS AS HANDLE. 
hPDS = DATASET dsCustomerOrders:HANDLE. 
ASSIGN 
    cSourceType = "FILE" 
    cFile = "dsCustomerOrders.xml" 
    cReadMode = ? 
    cSchemaLocation = ? 
    lOverrideDefaultMapping = FALSE. 
returnValue = hPDS:READ-XML(cSourceType, cFile, cReadMode, cSchemaLocation, 
                            lOverrideDefaultMapping). 
IF returnValue = FALSE THEN DO: 
    MESSAGE "READ-XML on ProDataSet failed!" VIEW-AS ALERT-BOX.  
    RETURN. 
END. 
ELSE  
    MESSAGE "Successful READ-XML on : " hPDS:NAME VIEW-AS ALERT-BOX. 
/*** After the method call, your application does work with its data. ***/ 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095